package com.cf.purchase.controller;

import com.cf.purchase.service.PlanService;
import com.cf.util.PurchaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author: chenfeng
 * @time: 2019/6/17 18:33
 */
@Controller
@RequestMapping("plan")
public class PlanController {

    @Autowired
    private PlanService planService;

    @GetMapping("getPlan")
    @ResponseBody
    public PurchaseResponse getPlan(@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize, @RequestParam(value = "limitStart", defaultValue = "0") Integer limitStart, String searchparameter) {
        try {
            return planService.getPlan(pageSize, limitStart, searchparameter);
        } catch (Exception e) {
            e.printStackTrace();
            return PurchaseResponse.failure("系统异常");
        }
    }
    
    @GetMapping("addOrEditPlan")
    @ResponseBody
    public PurchaseResponse addOrEditPlan(String plan, String goodsArray){
        try {
            return planService.addOrEditPlan(plan,goodsArray);
        } catch (Exception e) {
            e.printStackTrace();
            return PurchaseResponse.failure("系统异常");
        }
    }

    @GetMapping("")
    public String index() {
        return "plan";
    }


}
